package com.gosophia.conferenceManagement.summary.ws.test.integration;

import junit.framework.Assert;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;

import com.gosophia.commons.DozerChangeUtil;
import com.gosophia.commons.exception.BusinessException;
import com.gosophia.commons.exception.ConcurrencyException;
import com.gosophia.commons.exception.ParameterException;
import com.gosophia.commons.exception.TechnicalException;
import com.gosophia.conferenceManagement.summary.dao.SummaryJobDataDao;
import com.gosophia.conferenceManagement.summary.dto.SummaryJobDataDTO;
import com.gosophia.conferenceManagement.summary.entity.SummaryJobData;
import com.gosophia.conferenceManagement.summary.ws.SummaryWebService;
import com.gosophia.taskManagement.dao.JobDao;
import com.gosophia.taskManagement.dto.JobDTO;
import com.gosophia.taskManagement.entity.Job;
import com.gosophia.userManagement.dto.UserInfoDTO;


@ContextConfiguration(locations = { "classpath*:moduleContext.xml",
"classpath:applicationContext-test.xml" })
public class ITSummaryWebServiceImpl extends
        AbstractTransactionalJUnit4SpringContextTests{
    @Autowired
    private SummaryWebService summaryWebService;
    @Autowired
    private SummaryJobDataDao summaryJobDataDao;
    @Autowired
    private JobDao jobDao ;
    
    @Test
    public void testFindSummaryJobDataByJobDataId() throws ParameterException, ConcurrencyException, TechnicalException, BusinessException{
       SummaryJobDataDTO summaryJobDataDTO =  summaryWebService.findSummaryJobDataByJobDataId(1L);
       Assert.assertEquals("处理意见", summaryJobDataDTO.getOpinion());
    }
    @Test
    public void testFindFindSummaryJobDataByJobDataIdNoEntity() throws ParameterException, ConcurrencyException, TechnicalException, BusinessException{
        SummaryJobDataDTO summaryJobDataDTO=summaryWebService.findSummaryJobDataByJobDataId(10000L);
        Assert.assertNull(summaryJobDataDTO);
    }
    @Test(expected=IllegalArgumentException.class)
    public void testFindFindSummaryJobDataByJobDataIdWithNull() throws ParameterException, ConcurrencyException, TechnicalException, BusinessException{
        summaryWebService.findSummaryJobDataByJobDataId(null);
    }
    @Test
    public void testUpdateSummaryJobData() throws ParameterException, ConcurrencyException, TechnicalException, BusinessException{
        SummaryJobDataDTO summaryJobDataDTO = summaryWebService.findSummaryJobDataByJobDataId(1L);
        summaryJobDataDTO.setOpinion("aa");
        UserInfoDTO u = new UserInfoDTO();
        u.setUserInfoId(2L);
        summaryJobDataDTO.setNextApproval(u);
        Job job = jobDao.get(1L);
        JobDTO jobDTO = DozerChangeUtil.changeBeforeToAfter(job, JobDTO.class);
        summaryJobDataDTO.setJobDTO(jobDTO);
        summaryWebService.updateSummaryJobData(summaryJobDataDTO);
        summaryJobDataDao.clearSession();
        SummaryJobData s = summaryJobDataDao.get(1L);
        Assert.assertEquals("马小黑", s.getNextApproval().getUserName());
        Assert.assertEquals("aa", s.getOpinion());
    }
    @Test(expected=IllegalArgumentException.class)
    public void testUpdateSummaryJobDataIdNull() throws ParameterException, ConcurrencyException, TechnicalException, BusinessException{
        summaryWebService.updateSummaryJobData(null);
    }
    
//    @Test
//    public void testFindPreSummaryJobDataByJobDataId() throws ParameterException, ConcurrencyException, TechnicalException, BusinessException{
//        SummaryJobDataDTO s = summaryWebService.findPreSummaryJobDataByJobDataId(1L);
//        Assert.assertEquals("处理意见", s.getOpinion());
//    }
//    
//    @Test
//    public void test() throws BusinessException{
//        SummaryJobDataDTO s = new SummaryJobDataDTO();
//        DocumentDTO document = new DocumentDTO();
//        document.setDocumentPath("c:");
//        document.setDocumentVersion("1.1");
//        s.setOnlineDocumentDTO(document);
//        s.setOpinion("dfrdgv");
//        UserInfoDTO u = new UserInfoDTO();
//        u.setUserInfoId(1000L);
//        s.setNextApproval(u);
//        
//        summaryWebService.HandleConferenceTurningSummary(10561L, 1000L, s);
//    }
}
